<template>
	<view class="page_wrapper">
		<view class="calc_list_block">
			<view class="calc" v-for="(calc, index) in calcList" :key="index">
				{{calc.firstNum}} {{calc.calcType}} {{calc.secondNum}} = 
			</view>
		</view>
		<view class="btns_block">
			<view class="fcz_btn download_btn" @click="returnIndex()">返回首页</view>
			<view class="fcz_btn online_btn" @click="onlineCalcs()">开始测试</view>
		</view>
	</view>
</template>

<script>
	import {request} from '@/utils/request.js'
	import {utils} from '@/utils/utils.js'
	import {storageData} from '@/utils/storageData.js'
	export default {
		data() {
			return {
				examId: 0,
				score: '',
				useTimeTxt: '',
				mathExam: {},
				calcList: []
			}
		},
		onLoad(option) {
			this.examId = option.examId
			this.fetchData()
		},
		methods: {
			fetchData() {
				uni.showLoading()
				request.get( 
					'/mathExams/id,' + this.examId, {}
				).then(res => {
					uni.hideLoading()
					console.log(res)
					this.mathExam = res
					this.score = this.mathExam.rightCount / this.mathExam.calcTotalCount * 100
					this.useTimeTxt = utils.int2TimeTxt(this.mathExam.useTime)
					this.calcList = res.calcLogList
				}).catch(err => {
					uni.hideLoading()
					console.log(err)
				})
			},
			onlineCalcs() {
				// 备份一份题，然后开始答题
				uni.showLoading()
				request.postJson( 
					`/mathExams/id,${this.examId}/clone`, {}
				).then(res => {
					uni.hideLoading()
					console.log(res)
					uni.navigateTo({
						url: '/pages/mathCalcs/onlineTest?examId=' + res.id
					})
				}).catch(err => {
					uni.hideLoading()
					console.log(err)
				})
				
			},
			returnIndex() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
		},
		onShareAppMessage(res) {
			if (res.from === 'button') {
				// 来自页面内分享按钮
				console.log(res.target);
			}
			return {
				title: '萌芽学口算：学习好帮手',
				path: '/pages/index/index',
				mpId: 'wxe9f0922a16331d4b', //此处配置微信小程序的AppId
				imageUrl: 'https://fcz.oss-cn-beijing.aliyuncs.com/f/fbkzvdomazmqarrq.png'
			}
		},
		onShareTimeline(res) {
			const userInfo = storageData.getLoginUser()
			return {
				title: '萌芽学口算：学习好帮手',
				path: '/pages/index/index',
				mpId: 'wxe9f0922a16331d4b', //此处配置微信小程序的AppId
				imageUrl: 'https://fcz.oss-cn-beijing.aliyuncs.com/f/fbkzvdomazmqarrq.png'
			}
		},
	}
</script>

<style lang="scss">
.page_wrapper{
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	.calc_list_block{
		flex: 1;
		display: flex;
		flex-wrap: wrap;
		align-content: flex-start;
		overflow: scroll;
		.calc{
			width: 25%;
			height: 50px;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
	.btns_block{
		height: 60px;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 0px 20px;
		.fcz_btn{
			height: 40px;
			color: white;
			background-color: #67C23A;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 5px;
		}
		.online_btn{
			flex: 1;
		}
		.download_btn{
			flex: 0.5;
			margin-right: 20px;
		}
	}
}
</style>
